package algorithm.poj.p1000;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLDecoder;
import java.util.StringTokenizer;


/**
 * 分析：
 * 实现：
 * 经验：
 * 教训：
 * 
 * @author wong.tong@gmail.com
 *
 */
public class P1528 {

	public static void main(String[] args) throws Exception {

		InputStream input = null;
		if (false) {
			input = System.in;
		} else {
			URL url = P1528.class.getResource("P1528.txt");
			File file = new File(URLDecoder.decode(url.getPath(), "UTF-8"));
			input = new FileInputStream(file);
		}
		
		BufferedReader stdin = new BufferedReader(new InputStreamReader(input));

		int[] ps = primes((int)Math.sqrt(60000)+1);
		StringBuffer sb = new StringBuffer("");
		sb.append("PERFECTION OUTPUT\n");
		String line = stdin.readLine();
		StringTokenizer st = new StringTokenizer(line);
		while (st.hasMoreTokens()) {
			String s = st.nextToken();
			int n = Integer.valueOf(s);
			if (n == 0) break;
			int[][] fs = factors(n, ps);
			int m = 1;
			for (int i = 0; i < fs.length; i ++) {
				int p = fs[i][0];
				int a = fs[i][1];
				m *= (int)(Math.pow(p, a+1)-1)/(p-1);
			}
			for (int i = 0; i < 5-s.length(); i ++) sb.append(" ");
			sb.append(s);
			if (m < n*2) {
				sb.append("  DEFICIENT\n");
			} else if (m > n*2) {
				sb.append("  ABUNDANT\n");
			} else {
				sb.append("  PERFECT\n");
			}
			
		}
		sb.append("END OF OUTPUT");
		System.out.println(sb);
	}
	
	/**
	 * return all primes less than m 
	 * @param m
	 * @return
	 */
	public static int[] primes(int m) {
		
		if (m <= 1) {
			return new int[0];
		} else if (m == 2) {
			return new int[] {2};
		} else {
			int count = 0;
			int[] ns = new int[m];
			for (int i = 0; i < m; i ++) ns[i] = i;
			ns[0] = ns[1] = 0;
			
			int index = 2;
			int p = 0;
			while (index < m) {
				if (ns[index] != 0) {
					count ++;
					p = index;
					for (int j = (p<<1); j < m; j += p) {
						ns[j] = 0;
					}
				}
				index ++;
			}
			
			index = 0;
			int[] ps = new int[count];
			for (int i = 0; i < m; i ++) {
				if (ns[i] != 0) {
					ps[index ++] = i;
				}
			}

			return ps;
		}
	}

	/**
	 * ps is all primes number less than sqrt(n)
	 * @param n
	 * @param ps
	 * @return
	 */
	public static int[][] factors(long n, int[] ps) {

		int[] as = new int[ps.length];
		for (int i = 0; i < as.length; i ++) {
			if (n >= ps[i]) {
				while (n%ps[i] == 0) {
					n /= ps[i];
					as[i] ++;
				}
			}
		}
		
		int count = 0;
		for (int i = 0; i < as.length; i ++) {
			if (as[i] > 0) {
				count ++;
			}
		}
		if (n > 1) count ++;
		
		int[][] fs = new int[count][];
		int index = 0;
		for (int i = 0; i < as.length; i ++) {
			if (as[i] > 0) {
				fs[index] = new int[2];
				fs[index][0] = ps[i];
				fs[index][1] = as[i];
				index ++;
			}
		}
		if (n > 1) {
			fs[count-1] = new int[2];
			fs[count-1][0] = (int)n;
			fs[count-1][1] = 1;
		}
		return fs;
	}

}